/**
 * JAVACC DEMO 1.0
 * @Package com.apache.passport.service.plugins
 */
package com.apache.passport.service.plugins;

import com.apache.api.manager.PluginConnector;
import com.apache.api.vo.ParamsVo;
import com.apache.api.vo.ResultEntity;
import com.apache.database.constant.Validator;
import com.apache.database.db.IDao;
import com.apache.database.model.MethodParam;
import com.apache.passport.entity.SynInfo;

/**
 * description:  根据系统名称查询外部系统同步参数
 */
public class SysEnameQueryPlugin implements PluginConnector {
    protected IDao synInfoDao;

    public void setSynInfoDao(IDao synInfoDao) {
        this.synInfoDao = synInfoDao;
    }

    /**
     * TODO 简单描述该方法的实现功能（可选）.  
     * @see PluginConnector#execute(ParamsVo)
     */
    @Override
    public Object execute(ParamsVo paramsvo) throws Exception {
        ResultEntity result = new ResultEntity();
        result.setResult("true");
        String sysEname = (String) paramsvo.getParams("sysEname");
        if (Validator.isEmpty(sysEname)) {
            result.setEntity("F");
            result.setMessage("系统名称不能为空");
            return result;
        }

        SynInfo synInfo = (SynInfo) getSysInfoByEname(sysEname);
        if (Validator.isEmpty(synInfo)) {
            result.setEntity("F");
            result.setMessage("未查询到此系统");
            return result;
        }
        result.setEntity("T");
        result.setEntity(synInfo);
        result.setMessage("系统参数查询成功");
        return result;
    }

    public Object getSysInfoByEname(String sysEname) {
        String sql = synInfoDao.getSql(3);
        MethodParam param = new MethodParam("BySysEname", "", sql,
                "com.apache.passport.entity.SynInfo");
        param.setParams("sysEname", sysEname);
        return synInfoDao.selectSingle(param);
    }

}
